package xyz.xuminghai.javafx_learn.scene.paint;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

import java.io.FileNotFoundException;
import java.net.URL;

/**
 * 2023/7/31 10:39 星期一<br/>
 * ImagePattern类用图像图案填充形状。用户可以指定锚矩形，
 * 它定义图像相对于形状左上角的位置、宽度和高度。如果形状超出锚定矩形，则图像会平铺。
 *
 * @author xuMingHai
 */
public class ImagePatternApp extends Application {

    private final BorderPane root = new BorderPane();

    public static void main(String[] args) {
        Application.launch(args);
    }


    @Override
    public void init() throws Exception {
        String fileName = "image-pattern-app.jpg";
        URL url = getClass().getResource(fileName);
        if (url == null) {
            throw new FileNotFoundException(fileName);
        }

        Circle circle = new Circle(100.0,
                new ImagePattern(new Image(url.toExternalForm())));
        root.setCenter(circle);
    }

    public void start(Stage primaryStage) {
        primaryStage.setTitle(getClass().getSimpleName());
        Scene scene = new Scene(root, 800, 600);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

}
